package com.woniuxy.config;

import com.baidu.aip.ocr.AipOcr;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.alibaba.fastjson.JSON;

import java.util.HashMap;
import java.util.Map;

@Component
public class Sample {
    @Autowired
    //private KeyWordMapper keyWordMapper;

    // 设置APPID/AK/SK
    public static final String APP_ID = "19252617";
    public static final String API_KEY = "Hzf8hiiFY7v3GcinQI7GyAIK";
    public static final String SECRET_KEY = "x7I2IoOU5CykNuC7mU3rgCQ93F1qoQ74";

    // 初始化用户对象
    public static AipOcr init() {
        // 初始化一个AipOcr
        AipOcr client = new AipOcr(APP_ID, API_KEY, SECRET_KEY);
        // 可选：设置网络连接参数
        client.setConnectionTimeoutInMillis(2000);
        client.setSocketTimeoutInMillis(60000);

        return client;
    }

    public Map sample(String image ) {
        // 传入可选参数调用接口
        HashMap<String, String> options = new HashMap<String, String>();
        options.put("multi_detect", "true");

        AipOcr client = init();

        // 参数为本地图片路径
        //String image = "C:\\Users\\User\\Desktop\\images\\cph.jpg";
        JSONObject res = client.plateLicense(image, options);
        System.out.println(res.toString(2));
        Map map = (Map) JSON.parse(res.toString());

        return  map;
    }





}